package mspbots.cw.callbacks.core;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.log4j.Log4j2;
import mspbots.cw.common.RabbitKeys;
import mspbots.cw.common.ResultMsg;
import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author billb
 */
@Log4j2
public abstract class AbstractToolsUtil {

    protected ObjectMapper objectMapper;
    protected RabbitMessagingTemplate messagingTemplate;
    protected RabbitMessagingTemplate rabbitMessagingTemplate;

    protected void sendEntity(String key, ResultMsg resultMsg) {
        this.rabbitMessagingTemplate.convertAndSend(RabbitKeys.BASE_EXCHANGE_NAME, key, resultMsg);
    }

    @Autowired
    public void setObjectMapper(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    @Autowired
    public void setMessagingTemplate(RabbitMessagingTemplate messagingTemplate) {
        this.messagingTemplate = messagingTemplate;
    }

    @Autowired
    public void setRabbitMessagingTemplate(RabbitMessagingTemplate rabbitMessagingTemplate) {
        this.rabbitMessagingTemplate = rabbitMessagingTemplate;
    }
}
